<template>
  <div>
    <van-submit-bar
      :price="Number($store.state.common.total*100)"
      button-text="支付"
      @submit="onSubmit"
      tip-icon="info-o"
      :disabled="bool"
    >
      <van-checkbox :value="$store.state.common.isCheAll" @click="checkAll">全选</van-checkbox>
      <template #tip>您的订单为虚拟订单(支付后不发货),请勿支付大额款项!</template>
    </van-submit-bar>
  </div>
</template>

<script>
import Vue from "vue";
import moment from "moment";
import { SubmitBar,Dialog,Toast} from "vant";

Vue.use(SubmitBar);
Vue.use(Dialog);
Vue.use(Toast);
export default {
  data() {
    return {
      WIDout_trade_no: "",
      WIDsubject: "",
      WIDtotal_fee: 0,
      bool:true
    };
  },
  methods: {
    onSubmit() {
      let time = moment(Date.now()).format("YYYYMMDDhhmmss");
      let a = parseInt(Math.random() * 1000000);
      this.WIDout_trade_no = time + a;
      let href =
        "https://m.28sjw.com/alipay_wap/alipayapi.php?WIDout_trade_no=" +
        this.WIDout_trade_no +
        "&WIDsubject=" +
        this.WIDsubject +
        "&WIDtotal_fee=" +
        this.WIDtotal_fee;
      window.open(href, "_brank");
      Dialog.confirm({
        title: "支付成功？",
        message: "如果您已经支付成功，请点击“请定”",
      })
        .then(() => {
          this.$http.get('/zfb/order/orderPayStatusCheck.php?_oid='+this.WIDout_trade_no).then(ret=>{
              ret.data.finish_time ? Toast.success('购买成功') : Toast.fail('支付失败')
          })
        })
        .catch(() => {
          // on cancel
        });
    },
    checkAll() {
      this.$store.commit(
        "common/setIsCheAll",
        !this.$store.state.common.isCheAll
      );
    },
  },
  computed: {
    total() {
      return this.$store.state.common.total;
    },
  },
  watch: {
    total(num) {
      this.WIDtotal_fee = Number(num);
      this.bool=num==0
    },
  },
  created() {
    this.$store.commit("common/setIsCheAll", false);
  },
};
</script>

<style scoped>
</style>